package assets_withdraw

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/assetsClient/rpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type AssetsWithDrawBankFindLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// b端提现管理--银行字典--查询
func NewAssetsWithDrawBankFindLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AssetsWithDrawBankFindLogic {
	return &AssetsWithDrawBankFindLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AssetsWithDrawBankFindLogic) AssetsWithDrawBankFind(req *types.AssetsWithDrawBankFindReq) (resp *types.AssetsWithDrawBankFindRes, err error) {
	rpc_req := &rpc.GetWithDrawBankRequest{
		Name: req.BankName,
		Code: req.BankCode,
		Page: &rpc.Page{
			Page:      req.Page.Page,
			PageSize:  req.Page.PageSize,
			SortOrder: req.Page.SortOrder,
		},
	}

	// 发送请求
	rpc_resp, err := l.svcCtx.AssetsRpc.Config.BankListPage(l.ctx, rpc_req)
	if err != nil {
		logx.Errorf("Call ModifyVipLevelInfos error: %v", err)
		return nil, err
	}

	// 处理请求返回的结果
	// 解析、组合数据
	resp = &types.AssetsWithDrawBankFindRes{}
	resp.Total = rpc_resp.ResHead.Count
	for _, d := range rpc_resp.Data {
		resp.Data = append(resp.Data, types.WithDrawBank{
			Id:       d.Id,
			BankName: d.BankName,
			BankCode: d.BankCode,
			BankLogo: d.BankLogo,
			Status:   d.Status,
		})
	}
	return
}
